Fix duplicate DbParameter naming uniquification#37430
Merged
roji merged 1 commit intodotnet:mainfrom Jan 3, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #37409 where duplicate DbParameter instances in a SQL tree were having their names uniquified multiple times, leading to incorrect parameter references. The issue occurs when SQL tree fragments are duplicated during query translation (e.g., in GroupBy operations).
Key Changes
- Added deduplication logic to track already-processed DbParameter instances using a dictionary keyed by DbParameter reference
- Refactored
ProcessDbParameterto returnRawRelationalParameterinstead of modifying the parameter in-place without returning a value - Added a test case demonstrating the GroupBy scenario that triggers SQL tree duplication
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/EFCore.Relational/Query/Internal/RelationalParameterProcessor.cs |
Added _processedDbParameters dictionary to cache processed DbParameters and prevent duplicate name uniquification; refactored ProcessDbParameter to return the created RawRelationalParameter |
test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs |
Added test FromSql_GroupBy_non_reducing_Select to verify the fix handles duplicated SQL tree fragments with DbParameters |
test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs |
Added SQL baseline for the new test showing the same @city parameter correctly used twice in the generated SQL |
AndriySvyryd
approved these changes
Jan 2, 2026
roji
added a commit
to roji/efcore
that referenced
this pull request
Jan 20, 2026
roji
added a commit
to roji/efcore
that referenced
this pull request
Jan 20, 2026
roji
added a commit
that referenced
this pull request
Feb 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #37409